<?php
    require_once(dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR ."core".DIRECTORY_SEPARATOR."functions.php");

    class dbConn
    {
        private $hostName = DB_LOCAL_HOST;//mysql7.000webhost.com
        private $user = DB_LOCAL_USER;//a2764691_admin
        private $password = DB_LOCAL_PASS;//N!krocks08
        private $dataBase = DB_LOCAL_DB;//a2764691_sdp

        private $result,$iResult;
        
        public function __construct(){}
        
        private function dbConnect()
        {
            $conn = mysql_connect($this->hostName,$this->user,$this->password)
                    or die("<h1>Could not connect to DATABASE</h1>");

            mysql_select_db($this->dataBase,$conn)
                    or die("<h1>Could not select the DATABASE</h1>");

            return $conn;
        }

        public function query($query)
        {
            $this->dbConnect();
            $this->result = mysql_query($query) or die("ERROR : ".mysql_error());
            return $this->result;
        }

        public function insert($query)
        {
            $this->dbConnect();
            $this->iResult = mysql_query($query) or die("Could not insert!".mysql_error());
            return $this->iResult;
        }

        public function num_rows($res)
        {
            $this->dbConnect();
            $result = mysql_num_rows($res);
            return $result;
        }

        public function fetch_array($res,$assoc=false)
        {
            $this->dbConnect();
            if(!$assoc)
            {
                $result = mysql_fetch_array($res);
            }
            else
            {
                $result = mysql_fetch_array($res, MYSQL_ASSOC);
            }
            return $result;
        }

        public function fetch_object($res)
        {
            $this->dbConnect();
            $result = mysql_fetch_object($res) or die("failed fetch object : ".mysql_error());
            return $result;
        }

        public function fetch_assoc($res)
        {
            $this->dbConnect();
            $result = mysql_fetch_assoc($res) or die("failed to fetch associative array : ".mysql_error());
            return $result;
        }
        /*
        public static function delete($query)
        {
            $this->dbConnect();
            $result = mysql_query($query) or die("Failed to delete".mysql_error());
            return $result;
        }
        */

    }

?>